/**
 * 
 */
package com.dashu.authority.util;

import java.util.HashMap;
import java.util.Map;

/**
 * @author jiesion
 * update 2016年4月12日 下午3:13:39
 */
public class ResultMapUtil {
	public final static Integer SUCCESSSTATUS = 1;//接口成功状态

	public final static Integer FAILDSTATUS = 0;//接口失败状态

	public final static String EMPTYSTR = "";//空字符串

	public final static String EMPTYARRAY = "[]";//空数组

	public final static String EMPTYJSON = "{}";//空json

	public final static String STATUS = "status"; //状态key

	// public final static String MESSAGE = "message";

	public final static String ERRORCODE = "errorCode";//错误代码key

	public final static String ERRORMSG = "errorMsg";//消息key

	public final static String REQUEST = "request";//请求url key

	public final static String DATA = "data";//返回数据  key
	
	public final static Integer TRUEVALUE = 1;
	public final static Integer FALSEVALUE = 0;
	public final static Integer YES = 1;
	public final static Integer NO = 0;
	public final static Integer ENABLE = 1;
	public final static Integer DISABLED = 0;
	
	
	

	public static Map<Object, Object> resultMap(ResultBean reBean) {
		Map<Object, Object> result = new HashMap<Object, Object>();
		
		Integer status = reBean.getStatus();
		String errorCode = reBean.getErrorCode();
		String errorMsg = reBean.getErrorMsg();
		String request = reBean.getRequest();
		Object data = reBean.getData();
		
		if (status == null || "".equals(status)) {
			result.put(STATUS, FAILDSTATUS);
		} else {
			result.put(STATUS, status);
		}
		
		if (errorCode == null || "".equals(errorCode)) {
			result.put(ERRORCODE, EMPTYSTR);
		} else {
			result.put(ERRORCODE, errorCode);
		}

		if (errorMsg == null || "".equals(errorMsg)) {
			result.put(ERRORMSG, EMPTYSTR);
		} else {
			result.put(ERRORMSG, errorMsg);
		}
		
		if (request == null || "".equals(request)) {
			result.put(REQUEST, EMPTYSTR);
		} else {
			result.put(REQUEST, request);
		}
		
		if (data == null || "".equals(data)) {
			result.put(DATA, EMPTYJSON);
		} else {
			result.put(DATA, data);
		}
		
		return result;
	}
}
